let upbase = []
let db=wx.cloud.database()
import {
  http
} from '../../utils/http'
Page({
  data: {
    src:'',
    srcs:'',
    imgs: [],
    imgssub: [],
    count: 3,
    tabArr: {
      curHdIndex: 0,
      curBdIndex: 0
    },
    /* 文件使用身份证查询 */
    idCard: "",
    file: {
      sxzl_file: "",
      zj_file: "",
      sddc_file: "",
      else_file: "",
    },
    /* 文件使用身份证查询 */
  },
  
  tabFun: function(e){  
    //获取触发事件组件的dataset属性  
    var _datasetId=e.target.dataset.id;  
    var _obj={};  
    _obj.curHdIndex=_datasetId;  
    _obj.curBdIndex=_datasetId;  
    this.setData({  
      tabArr: _obj  
    });  
  },  

  /*  查询身份证-searchbysid */
  searchbysid() {
    let that = this
    http.request({
      url: '/findImageDataByIdCard',
      method: "GET",
      data: {
        idCard: this.data.idCard
      },
      success(data) {
        if (!data.data) {
          wx.showToast({
            title: `没有数据`,
            icon: 'fail',
            mask: true,
            duration: 1500,
          })
          return;
        }
        that.setData({
          "file": {
            sxzl_file: data.data.sxzl_file,
            zj_file: data.data.zj_file,
            sddc_file: data.data.sddc_file,
            else_file: data.data.else_file,

          }
        })
      }
    })
  },
  //上传图片
//上传图片
  upimage() {
    let that = this
    wx.chooseImage({
      count: 3, //需要上传图片的数量
      sizeType: ['original'], //原图还是压缩图
      sourceType: ['album', 'camera'], //从相机还是库选择
      success(res) {
        console.log(res)
        // 将图片渲染到界面
        console.log(res.tempFilePaths)
        //将拿到的图片地址链接赋值
        that.setData({
          src: res.tempFilePaths
        })
      }
    })
  },
  //显示改图片
  viewimager() {
    let that = this
    wx.previewImage({
      current: '',
      urls: that.data.src,
    })


  },
   tabFun: function(e){  
    //获取触发事件组件的dataset属性  
    var _datasetId=e.target.dataset.id;  
    var _obj={};  
    _obj.curHdIndex=_datasetId;  
    _obj.curBdIndex=_datasetId;  
    this.setData({  
      tabArr: _obj  
    });  
  },  
  //将图片上传云
  imagecloud() {
    let that = this
    wx.showLoading({
      title: '上传中',
    })
    let time = Date.parse(new Date()) / 1000
    wx.cloud.uploadFile({
      cloudPath: '2022-9-23/' + time, //上传图片的名字
      filePath: that.data.src[0], // 图片的临时地址
    }).then(res => {
      wx.hideLoading()
      wx.showToast({
        title: '上传成功',
      })
      console.log(res.fileID, i)
      upbase[i] = res.fileID

    }).catch(error => {
      console.log(error)
    })

  },
  upbase(){
    console.log("upbase的值",upbase)
    db.collection("ImageData").add({
      data:{
      src:upbase
    }
    })
    .then(res=>{
      wx.showToast({
        title: '上传成功',
      })
     })
     .catch(err=>{
       console.log(err)
     }
      )
    
  },
  //显示上传到数据库的
  baseimage(){
    let that=this
    db.collection("ImageData").get()
    .then(res=>{
      that.setData({
        srcs:res.data
      })
    })
    console.log(that.data.srcs)
  },
    

  





});



















